package com.lepu.flutterdemo.tab

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import com.idlefish.flutterboost.containers.FlutterBoostFragment
import com.lepu.flutterdemo.R
import io.flutter.embedding.android.FlutterFragment
import io.flutter.embedding.android.FlutterFragmentActivity
import kotlinx.android.synthetic.main.activity_tab.*


/**
 * @author yangqing
 * @time 2021/10/15 10:35
 * @describe
 */
class TabActivity : AppCompatActivity() {
    var commonFragment: Fragment = CommonFragment()
    lateinit var flutterFragment: FlutterFragment
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_tab)
//        flutterFragment = FlutterFragment.createDefault();//创建默认fragment
//        flutterFragment = FlutterFragment.withCachedEngine("my_engine_id_two").build()//通过缓存引擎创建fragment（引擎中制定了路由）
        flutterFragment =
            FlutterBoostFragment.CachedEngineFragmentBuilder().url("test_entry").build()////boost框架
        bottomNavigation.setOnNavigationItemSelectedListener { item ->
            if (R.id.main_three == item.itemId) {
                commonFragment = flutterFragment
            } else {
                commonFragment = CommonFragment()
            }
            supportFragmentManager.beginTransaction().replace(R.id.flContainer, commonFragment)
                .commit()
            return@setOnNavigationItemSelectedListener true
        }
        bottomNavigation.selectedItemId = R.id.main_two
        supportFragmentManager.beginTransaction().replace(R.id.flContainer, commonFragment).commit()
    }
}